//
//  NSOperations.m
//  RBIOSBase
//
//  Created by ren on 05/12/2017.
//  Copyright © 2017 bryan. All rights reserved.
//

#import "NSOperations.h"
#import <objc/runtime.h>

@implementation NSOperations

- (void)operations
{
	const char *currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);//得到当前线程的label
	const char *curLabel = dispatch_queue_get_label(dispatch_get_main_queue());
	if (strcmp(currentLabel, curLabel) == 0) {
		NSLog(@"equal");
	}
	
	NSOperationQueue *operationQueue = [NSOperationQueue new];
	[operationQueue setMaxConcurrentOperationCount:6];
	NSInvocationOperation *invocationOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(invocationAction:) object:@(1)];
//	[invocationOperation start];
	
	
	NSInvocationOperation *invocationOperation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(invocationAction:) object:@(2)];
	
	NSInvocationOperation *invocationOperation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(invocationAction:) object:@(3)];
	
	NSInvocationOperation *invocationOperation3 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(invocationAction:) object:@(4)];
	
//	[invocationOperation1 addDependency:invocationOperation];
//	[invocationOperation2 addDependency:invocationOperation1];
//	[invocationOperation3 addDependency:invocationOperation2];
	
	[invocationOperation2 addDependency:invocationOperation3];
	[invocationOperation1 addDependency:invocationOperation2];
	[invocationOperation addDependency:invocationOperation1];
	
	[operationQueue addOperation:invocationOperation];
	[operationQueue addOperation:invocationOperation1];
	[operationQueue addOperation:invocationOperation2];
	[operationQueue addOperation:invocationOperation3];
	
}

- (void)invocationAction:(id)number
{
	sleep(3);
	NSLog(@"invocationOperation---->%ld", [number integerValue]);
}


@end
